/**
 * @file		TemperatureSensor.h
 * @brief		Temperature Sensor
 * @note		None
 * @attention	None
 * 
 * <B><I>ALL RIGHTS RESERVED, COPYRIGHT&copy; SOCIONEXT INCORPORATED 2016</I></B>
 */

/** @weakgroup TemperatureSensor_overview
@{
	Temperature Sensor base function.<br>
	Temperature sensors will issue a warning when the temperature of the chip becomes too hot.<br>
	<br>
	Control parameter setting<br>
	- Temperature Sensor I/F Config : Each sensor setting (Temperature Sensor#0)<br>
	- Reset setting : Reset release<br>
	- Enablement setting : Valid enablement<br>
	- Hysteresis setting : 0 degree<br>
	- Measurement time setting :<br>
		- 1st cycle time after enablement : 4279<br>
		- Cycle time 2nd later : 4128<br>
	- Mask setting for each interrupt : <br>
		- Interrupt for the high temperature excess alarm : Interrupt request enablement<br>
		- Interrupt for the nearby high temperature alarm : Interrupt request enablement<br>
		- Interrupt for the nearby low temperature alarm : Interrupt request enablement<br>
		- Interrupt for the low temperature excess alarm : Interrupt request enablement<br>

@}*//* --- end of TemperatureSensor_overview */

/** @weakgroup TemperatureSensor_sequence
@{
	- @ref TemperatureSensor_sequence
	- @ref TemperatureSensor_sample
	
	@section TemperatureSensor_sequence Sequence example of Temperature Sensor.
	@image html TemperatureSensor.png
	<br>

	<hr>
	@section TemperatureSensor_sample Sample code
	The example of Temperature Sensor is as follows.

	@code
	void TemperatureSensor_Sample()
	{
		int ret;
		T_TEMP_SENSOR_BUFFER buff;
		
		// set Buffer.
		buff.hi_full_temp	= 0x00000140;	//  40 degree
		buff.hi_near_temp	= 0x00000100;	//  32 degree
		buff.lo_full_temp	= 0xFFFFFFB0;	// -10 degree
		buff.lo_near_temp	= 0xFFFFFF88;	// -15 degree
		ret = iTemperatureSensorSetBuffer(&buff);
		if (ret != 0) {
			return;
		}
		
		// set notification : enable.
		ret = iTemperatureSensorNotification();
		if (ret != 0) {
			return;
		}
		
		// start.
		ret = iTemperatureSensorStart();
		if (ret != 0) {
			iTemperatureSensorStop();
			return;
		}
	}
	@endcode

@}*//* --- end of TemperatureSensor_sequence */

#ifndef _TEMP_SENSOR_H_
#define _TEMP_SENSOR_H_

/** @weakgroup TemperatureSensor_definition
@{*/

/** Interrupt type (Notification data) */
#define	D_TEMP_SENSOR_INT_LF	(0x00000001)		/**< low temperature excess Interrupt.		*/
#define	D_TEMP_SENSOR_INT_LN	(0x00000002)		/**< nearby low temperature Interrupt.		*/
#define	D_TEMP_SENSOR_INT_HN	(0x00000003)		/**< nearby high temperature Interrupt.		*/
#define	D_TEMP_SENSOR_INT_HF	(0x00000004)		/**< high temperature excess Interrupt.		*/

/** Buffer data */
typedef struct {
	unsigned long		hi_full_temp;	/**< Threshold temperature setting of the high temperature excess.	*/
	unsigned long		hi_near_temp;	/**< Threshold temperature setting of the nearby high temperature.	*/
	unsigned long		lo_near_temp;	/**< Threshold temperature setting of the nearby low temperature.	*/
	unsigned long		lo_full_temp;	/**< Threshold temperature setting of the low temperature excess.	*/
} T_TEMP_SENSOR_BUFFER;

/* @} */	// TemperatureSensor_definition group

/** @weakgroup TemperatureSensor_func
@{*/

/**
Temperature Sensor start.
@retval  0 : success
@retval  3 : function error
*/
//#define SET_TEMPERATURE_SENSOR_ALL
#ifdef SET_TEMPERATURE_SENSOR_ALL
extern int iTemperatureAllSensorStart(void);
#endif
extern int iTemperatureSensorStart(void);

/**
Temperature Sensor stop.
@retval  0 : success
@retval  3 : function error
*/
#ifdef SET_TEMPERATURE_SENSOR_ALL
extern int iTemperatureAllSensorStop(void);
#endif
extern int iTemperatureSensorStop(void);

/**
Temperature Sensor notification.
@param [in]	enable		notification enable.<br>
						0:disable, 1:enable
@retval  0 : success
@retval  1 : parameter error
*/
extern int iTemperatureSensorNotification(int enable);

/**
Set Temperature Sensor Buffer.
@param [in]	buff		Buffer data.
@retval  0 : success
@retval  1 : parameter error
*/
extern int iTemperatureSensorSetBuffer(T_TEMP_SENSOR_BUFFER const *const buff);
extern int iTemperatureSensorGetBuffer(T_TEMP_SENSOR_BUFFER *buff);

/**
Get Measured Temperature Data.
@param [out]	cmd		Command data (GET Temperature data).<br>
@retval  0 : success
@retval  3 : function error
*/
int iTemperatureSensorGetTemperatureData(unsigned *cmd);

/**
Get Temperature Sensor Interrupt type.
@retval		Interrupt type.<br>
			<ul><li>@ref D_TEMP_SENSOR_INT_LF
				<li>@ref D_TEMP_SENSOR_INT_LN
				<li>@ref D_TEMP_SENSOR_INT_HN
				<li>@ref D_TEMP_SENSOR_INT_HF</ul>
*/
extern unsigned long ulTemperatureSensorGetInterruptType(void);

/* @} */	// TemperatureSensor_func group

#endif	// _TEMP_SENSOR_H_
